<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function check(txtId,spanId,rex,str) {
            var txtObj = document.getElementById(txtId);
            var sObj = document.getElementById(spanId);
            if(rex.test(txtObj.value)){
                sObj.innerHTML = "验证成功";
                sObj.style.color = "green";
                return true;
            }else {
                sObj.innerHTML = str;
                sObj.style.color = "red";
                return false;
            }
        }

        function checkName() {
            return check('name','nameSpan',/^[\u4e00-\u9fa5]{2,}$/,'请输入两个以上的汉字');
        }
        function checkTel() {
            return check('psw','pswSpan',/^\d{6}$/,'请输入6位数字的密码');
        }
        function checkEmail() {
            return check('email','emailSpan',/^([a-zA-Z]|[0-9])+@[a-zA-Z0-9]+\.com$/,'请输入格式为xxx@xx.com的邮箱');
        }
        function checkBirth() {
            return check('birthday','birthSpan',/^\d{4}-\d{2}-\d{2}$/,'请输入格式为XXXX-XX-XX的的生日');
        }

        function checkForm() {
            var passName = checkName();
            var passTel = checkTel();
            var passEmail = checkEmail();
            var passBirth = checkBirth();
            return passName && passTel && passEmail && passBirth;
        }

    </script>
</head>
<body>
    <form action="add" method="get" onsubmit="return checkForm()">
        姓名：<input type="text" id="name" name="name" onblur="checkName()"><span id="nameSpan"></span><br>
        密码：<input type="text" id="psw" name="psw" onblur="checkTel()"><span id="pswSpan"></span><br>
        邮箱：<input type="text" id="email" name="email" onblur="checkEmail()"><span id="emailSpan"></span><br>
        生日：<input type="text" id="birthday" name="birthday" onblur="checkBirth()"><span id="birthSpan"></span><br>
        <input type="submit" value="提交">
    </form>
</body>
</html>